#!/bin/sh
BOARD_DIR="$(dirname $0)"

# For debug
echo "Target binary dir $BOARD_DIR"

# Copy Files to BINARY
cp $BOARD_DIR/../dragon/* -rfvd  $BINARIES_DIR

cd  $BINARIES_DIR
rm boot.fex
rm rootfs.fex
wait

$CONFIG_DIR/support/scripts/genimage.sh -c $BR2_EXTERNAL_T113_PATH/board/100ask/t113-pro/genimage.cfg
unix2dos sys_partition.fex
$BINARIES_DIR/script sys_partition.fex

unix2dos sys_config.fex
$BINARIES_DIR/script  sys_config.fex
cp -f   sys_config.bin config.fex

cp u-boot-sun8iw20p1.bin u-boot.fex

$BINARIES_DIR/update_boot0 boot0_sdcard.fex   sys_config.bin SDMMC_CARD > /dev/null
$BINARIES_DIR/update_chip boot0_sdcard.fex > /dev/null
$BINARIES_DIR/update_uboot -no_merge u-boot.fex sys_config.bin > /dev/null
$BINARIES_DIR/update_fes1  fes1.fex           sys_config.bin > /dev/null

ln -s boot.vfat boot.fex
ln -s rootfs.ext4 rootfs.fex

echo "-----------------update_mbr--------------------------"
$BINARIES_DIR/update_mbr  sys_partition.bin 4

echo "-----------------dragon pack--------------------------"
$BINARIES_DIR/dragon  image.cfg sys_partition.fex

